#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef pair < int , int > pii;
typedef vector < int > vec;
typedef vector < pii > veg;
typedef long long ll;
typedef double db;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch =='-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;
const int inf = 0x7fffffff;

int n;

namespace seg {
    struct node {
	bool isc; int cov,ad,had,hcov,mx,hmx;
	node() { isc = 0; mx = -inf; hmx = -inf; ad = had = cov = hcov = 0; }
	inline void cover(int v,int hv) {
	    if(!isc) { isc = true; hcov = hv; }
	    else hcov = max(hcov,hv);
	    cov = v; mx = v; hmx = max(hmx,hv); ad = 0;
	}
	inline void add(int ad1,int ad2) {
	    had = max(had,ad + ad2); hmx = max(hmx,mx + ad2); ad += ad1; mx += ad1;
	}
	inline void tadd(int ad1,int ad2) {
	    if(isc) cover(cov + ad1,cov + ad2);
	    else add(ad1,ad2);
	}
    } val[N << 2];
    inline void pu(int x) { val[x].mx = max(val[x << 1].mx,val[x << 1 | 1].mx); val[x].hmx = max(val[x].hmx,val[x].mx); }
    inline void pd(int x) {
	val[x << 1].tadd(val[x].ad,val[x].had); val[x << 1 | 1].tadd(val[x].ad,val[x].had);
	val[x].ad = val[x].had = 0;
	if(val[x].isc) {
	    val[x << 1].cover(val[x].cov,val[x].hcov); val[x << 1 | 1].cover(val[x].cov,val[x].hcov);
	    val[x].isc = val[x].cov = val[x].hcov = 0;
	} 
    }
    int qmax(int xl,int xr,int o = 1,int l = 1,int r = n) {
	if(xl == l && xr == r) return val[o].mx; int mid = l + r >> 1; pd(o);
	if(xr <= mid) return qmax(xl,xr,o << 1,l,mid); else if(xl > mid) return qmax(xl,xr,o << 1 | 1,mid + 1,r);
	else return max(qmax(xl,mid,o << 1,l,mid) , qmax(mid + 1,xr,o << 1 | 1,mid + 1,r));
    }
    int hqmax(int xl,int xr,int o = 1,int l = 1,int r = n) {
	if(xl == l && xr == r) return val[o].hmx; int mid = l + r >> 1; pd(o);
	if(xr <= mid) return hqmax(xl,xr,o << 1,l,mid); else if(xl > mid) return hqmax(xl,xr,o << 1 | 1,mid + 1,r);
	else return max(hqmax(xl,mid,o << 1,l,mid) , hqmax(mid + 1,xr,o << 1 | 1,mid + 1,r));
    }
    void plus(int xl,int xr,int v,int o = 1,int l = 1,int r = n) {
	if(xl == l && xr == r) return val[o].tadd(v,v); int mid = l + r >> 1; pd(o);
	if(xr <= mid) plus(xl,xr,v,o << 1,l,mid); else if(xl > mid) plus(xl,xr,v,o << 1 | 1,mid + 1,r);
	else plus(xl,mid,v,o << 1,l,mid),plus(mid + 1,xr,v,o << 1 | 1,mid + 1,r); pu(o);
    }
    void cover(int xl,int xr,int v,int o = 1,int l = 1,int r = n) {
	if(xl == l && xr == r) return val[o].cover(v,v); int mid = l + r >> 1; pd(o);
	if(xr <= mid) cover(xl,xr,v,o << 1,l,mid); else if(xl > mid) cover(xl,xr,v,o << 1 | 1,mid + 1,r);
	else cover(xl,mid,v,o << 1,l,mid),cover(mid + 1,xr,v,o << 1 | 1,mid + 1,r); pu(o);
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in; for(int i = 1;i <= n;i++) seg :: cover(i,i,in);
    int m = in;
    while(m--) {
	char op = getchar(); while(!isalpha(op)) op = getchar(); int x = in,y = in,z;
	if(op == 'Q') printf("%d\n",seg :: qmax(x,y));
	else if(op == 'A') printf("%d\n",seg :: hqmax(x,y));
	else if(op == 'P') z = in,seg :: plus(x,y,z);
	else z = in,seg :: cover(x,y,z);
    } return 0;
}
